<?php
/**
 * 团检单位
 *
 * User: kaikaic
 * Date: 2018/10/25
 * Time: 22:41
 */

namespace app\exam\service;

use service\BasicService;
use think\Db;

class EnterpriseService extends BasicService {

    public function init() {
        $this->dataTable = ['ExamEnterprise'];
    }

    public function listAll($tableIndex=0) {
        $where = array('status'=>1);
        return Db::name($this->dataTable[$tableIndex])->where($where)->select();
    }

    public function listEnterprise() {
        $records = $this->listAll();

        $enterprises = array();
        for ($i=0; $i<count($records); $i++) {
            $enterprises[$records[$i]['id']] = $records[$i]['name'];
        }

        return $enterprises;
    }

    /**
     * 当前排序最大值,新纪录自动+1
     */
    public function getMaxSort($tableIndex=0) {
        return Db::name($this->dataTable[$tableIndex])->max('sort');
    }
}

